package com.my.socket.nio.v31;

import java.net.InetSocketAddress;
import java.nio.channels.ServerSocketChannel;

/**
 * Created by ZhongGang
 * at 2018/8/21 17:58
 */
public class Server {
    private ServerSocketChannel serverSocketChannel;

    public Server(String hostname, int port) throws Exception {
        this.serverSocketChannel = ServerSocketChannel.open();
        this.serverSocketChannel.bind(new InetSocketAddress(hostname, port));
        this.serverSocketChannel.configureBlocking(false);
    }

    public void start() throws Exception {
        for (int i = 0; i < 3; i++) {
            Reactor reactor = new Reactor(this.serverSocketChannel);
            new Thread(reactor).start();
        }
    }

    public static void main(String[] args) throws Exception {
        Server server = new Server("127.0.0.1", 9999);
        server.start();
    }
}
